<%@ page import="myschool.util.MybatisUtil" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="myschool.dao.StudentDao" %>
<%@ page import="myschool.entity.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="myschool.util.StrUtil" %>
<%@ page import="myschool.service.StudentService" %>
<%@ page import="myschool.entity.Page" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: oldliu
  Date: 2023-06-05
  Time: 11:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .hide {
            pointer-events: none;
            color: gray;
        }
    </style>
    <script src="js/jquery-3.6.3.min.js.txt"></script>
</head>
<body>
<%@include file="checkLogin.jsp"%>
<div>
    <%
        String sname = StrUtil.toStr(request.getParameter("sname"));
        String tel = StrUtil.toStr(request.getParameter("tel"));
        String QQ = StrUtil.toStr(request.getParameter("QQ"));
        int pageNo = StrUtil.toInt(request.getParameter("pageNo"), 1);

        Date end = StrUtil.toDate(request.getParameter("end"));
        Date start = StrUtil.toDate(request.getParameter("start"));
        Page<Student> p = StudentService.ME.page(pageNo, Page.PAGESIZE, sname, tel, QQ,start, end);

    %>
    <form action="students.jsp" id="searchForm">
        <input type="hidden" name="pageNo" id="pageNo" value="1">
        <input name="sname" value="<%=sname%>" placeholder="姓名"/>
        <input name="tel" value="<%=tel%>" placeholder="电话"/>
        <input name="QQ" value="<%=QQ%>" placeholder="QQ号"/>
        入学时间从<input type="date" name="start" value="<%=StrUtil.toStr(start)%>"/>-
        <input type="date" name="end" value="<%=StrUtil.toStr(end)%>"/>
        <input type="submit" value="搜索">
    </form>
    <a href="addStudent.jsp">添加新生</a>
</div>
<table border="1" width="100%" cellpadding="0" cellspacing="0">
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>手机号</th>
        <th>微信</th>
        <th>QQ</th>
        <th>年级</th>
        <th>入学时间</th>
      <%--  <th>身份证照片</th>--%>
        <th>操作</th>
    </tr>
    <%

        for (Student stu : p.getData()) {
    %>
    <tr>
        <td><%=stu.getStuno()%>
        </td>
        <td><%=stu.getSname()%>
        </td>
        <td><%=stu.getSex()%>
        </td>
        <td><%=stu.getTelephone()%>
        </td>
        <td><%=stu.getWechat()%>
        </td>
        <td><%=stu.getQQ()%>
        </td>
        <td><%=stu.getGradeid()%>
        </td>
        <td><%=StrUtil.toStr(stu.getEnterdate())%>
        <%--<td style="overflow: hidden"><img src="<%=stu.getIdcardpic()%>" height="40px" width="100px"/> </td>--%>
        <td><a href="toUpdateStudent.jsp?stuno=<%=stu.getStuno()%>">修改</a> &nbsp;
            <a href="todelStudent.jsp?stuno=<%=stu.getStuno()%>">删除</a>
            <a href="showScore.do?stuno=<%=stu.getStuno()%>">查看成绩</a></td>

    </tr>

    <%}%>
</table>
<p id="pager">
    <%--
      href="pagNo=111&sname=xx&tel=xx&date=xxx
     --%>
    <a href="#" data-page="1">首页</a>
    <a  href="#" <% if(pageNo<=1)out.print("class='hide'");%> data-page="<%=pageNo-1%>">上一页</a>
    <span><input type="number" min="1" id="goto" value="<%=pageNo%>" max="<%=p.getPageTotal()%>" style="width: 48px" /><input type="button" id="go" value="Go"/>/<%=p.getPageTotal()%></span>
    <a  href="#" <% if(pageNo>=p.getPageTotal())out.print("class='hide'");%>  data-page="<%=pageNo+1%>">下一页</a>
    <a  href="#" data-page="<%=p.getPageTotal()%>">尾页</a>
</p>

<script>
  $(function () {
      $("#go").click(function () {
          let pageNo=$(this).prev().val();
          $("form#searchForm #pageNo").val(pageNo);
          $("form#searchForm").submit();
          return false;
      });
      $("#goto").keyup(function (event) {
          if(event.keyCode==13){
              let pageNo=$(this).val();
              $("form#searchForm #pageNo").val(pageNo);
              $("form#searchForm").submit();
              return false;
          }
          return false;
      });
     $("#pager a").click(function () {
         let pageNo=$(this).attr("data-page");
         $("form#searchForm #pageNo").val(pageNo);
         $("form#searchForm").submit();
         return false;
     });
  });
</script>
</body>
</html>
